package com.spring.demo.spring_boot.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.springframework.cache.annotation.Cacheable;

import com.spring.demo.spring_boot.base.mapper.BaseMapper;
import com.spring.demo.spring_boot.domain.RoleResource;

/**
 * 
 * @author 王辉阳
 * @date 2017年8月1日 下午6:11:28
 * @description 用户映射器
 */
@Mapper
public interface RoleResourceMapper extends BaseMapper<RoleResource> {

	// 查询后存入redis，建议以方法名
	@Cacheable(value = "get", keyGenerator = "keyGenerator")
	@Select("SELECT * FROM roles_resource WHERE id = #{id}")
	RoleResource get(@Param("id") String id);

	@Select("SELECT * FROM roles_resource  ")
	List<RoleResource> findAll();

	@Results(value = { //
			@Result(property = "roleId", column = "ROLE_ID", id = true), //
			@Result(property = "resId", column = "RES_ID", id = true) }) //
	@Select("SELECT * FROM roles_resource WHERE ROLE_ID  in  (${roleIds})")
	List<RoleResource> findByRoleIds(@Param("roleIds") String roleIds);

}